package com.kristin.zklock;

import java.util.concurrent.locks.Lock;

public class test {

//    private static Lock lock = new ReentrantLock();
    private static Lock lock = new ZkLock();

    private static int num = 1;

    static class ExecuteRunnable implements  Runnable {
        public void run() {

            lock.lock();

            if(num > 0 ) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                num --;
                System.out.println("减库存成功");
            } else {
                System.out.println("减库存失败");
            }

            lock.unlock();

        }
    }

    public static void main(String[] args) {
        new Thread(new ExecuteRunnable(), "线程一").start();
        new Thread(new ExecuteRunnable(), "线程二").start();
    }

}
